package com.qfhd.soft.cjzcore.UI.Custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qfhd.soft.cjzcore.R;
import com.qfhd.soft.cjzcore.UI.Listener.CJClickListener;
import com.qfhd.soft.cjzcore.UI.Listener.CJListener;

public class CJLoadingView extends RelativeLayout {
    private Context mContext;
    private AttributeSet mAttr;

    private RelativeLayout clickView;
    private TextView tx_tip;

    public CJLoadingView(Context context) {
        this(context, null);
    }

    public CJLoadingView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CJLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attr) {
        mContext = context;
        mAttr = attr;

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.loading_view_layout, this, true);
        clickView = mView.findViewById(R.id.loading_tip_rel);
        tx_tip = mView.findViewById(R.id.loading_tip);
    }

    public void setclickListener(CJClickListener listener){
        clickView.setOnClickListener(v -> {
            if (listener != null) {
                listener.onClick();
            }
        });
    }

    public void setfailTip(){
        tx_tip.setText("加载失败，点击重试");
    }

    public void setloadTip(){
        tx_tip.setText("加载中，请稍等");
    }
}
